#include "CodeTableFactory.h"

ICodeTable* CodeTableFactory::create(INode* root)
{
	buildTable(root);
	return new CodeTable(m_table);
}

void CodeTableFactory::buildTable(INode* node)
{
	if(NULL != node->left())
	{
			m_code.push_back(0);
			buildTable(node->left());
	}
	if(NULL != node->right())
	{
			m_code.push_back(1);
			buildTable(node->right());
	}
	if(node->getChar())
		m_table[node->getChar()] = m_code;
	m_code.pop_back();
}